package org.lanqiao.netctoss.controller.acount;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.lanqiao.netctoss.entity.Acount;
import org.lanqiao.netctoss.service.impl.AcountServiceImpl;

/**
 * Servlet implementation class AddAountServlet
 */
public class AddAcountServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddAcountServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("GBK");
		String aco_name = request.getParameter("name");
		String aco_card = request.getParameter("card");
		String aco_user = request.getParameter("user");
		String aco_psw1 = request.getParameter("psw1");
		String aco_psw2 = request.getParameter("psw2");
		String aco_psw=aco_psw1;
		String aco_tel = request.getParameter("tel");
		String aco_refcard = request.getParameter("recard");
		String aco_email = request.getParameter("email");
		int aco_pro = Integer.parseInt(request.getParameter("pro"));
		int aco_sex = Integer.parseInt(request.getParameter("radSex"));
		String aco_adress = request.getParameter("adress");
		int aco_code =Integer.parseInt(request.getParameter("code"));
		String aco_qq = request.getParameter("qq");
		//boolean b = acountBuss.insertAcount(new Acount(aco_name,aco_card,aco_user,aco_psw,aco_tel,aco_refcard,aco_email,aco_pro,aco_sex,aco_adress,aco_code,aco_qq));
		int i = new AcountServiceImpl().insertAcount(new Acount(aco_name,aco_card,aco_user,aco_psw,aco_tel,aco_refcard,aco_email,aco_pro,aco_sex,aco_adress,aco_code,aco_qq));
		if(i>0){
			PrintWriter out = response.getWriter();
			out.print("<script>alert('恭喜您，添加成功!');window.location.href='../view/account/account_add.jsp'</script>");
		}				
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
